home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 2000
/
MacHack 2000.toast
/
pc
/
The Hacks
/
Softshoe
/
Lisa's Mac Parts
/
Pascal Strings
/
PString.h
< prev
next >
Wrap
Text File
|
2000-06-23
|
4KB
|
92 lines
// PString.h
#ifndef PString_h
#define PString_h
#ifndef Assert_h
#include "Assert.h"
#endif
#ifndef Data_h
#include "Data.h"
#endif
#ifndef ConstPString_h
#include "ConstPString.h"
#endif
class PString
{
private:
const Data space;
const Data TextSpace() { return space.Tail( 1 ); }
const Data SpaceTail( uint32 where ) { return space.Tail( where + 1 ); }
const Data UnusedSpace() { return space.Tail( Length() + 1u ); }
enum{ maxStorageLength = maxuint8 + 1 };
public:
PString( Data );
PString( Data, PString );
PString( Data, ConstPString );
PString( Data, const uint8 * );
PString( Data, ConstData text );
uint8 Length() const { return space[0]; }
const URange32 Range() const { return URange32( 0, Length() ); }
uint32 StorageLength() const { return space.Length(); }
uint32 UnusedLength() const { return space.Length() - space[0] - 1; }
uint8& operator[]( uint32 i ) { Assert( i < Length() ); return space[i+1]; }
const uint8& operator[]( uint32 i ) const { Assert( i < Length() ); return space[i+1]; }
void Clear() { space[0] = 0; }
void Truncate( uint32 end );
void SetLength( uint32 );
const Data Text() { return Data( &space[1], Length() ); }
const ConstData Text() const { return ConstData( &space[1], Length() ); }
const ConstData Head( uint32 size ) const { return Text().Head( size ); }
const ConstData Tail( uint32 position ) const { return Text().Tail( position ); }
const ConstData Middle( URange32 range ) const { return Text().Middle( range ); }
const Data Head( uint32 size ) { return Text().Head( size ); }
const Data Tail( uint32 position ) { return Text().Tail( position ); }
const Data Middle( URange32 range ) { return Text().Middle( range ); }
void operator=( ConstData );
void operator=( ConstPString string ) { operator=( string.Text() ); }
void operator=( const PString& string ) { operator=( string.Text() ); }
void operator=( const uint8 *string ) { operator=( ConstPString( string ) ); }
void operator+=( uint8 c );
void operator+=( ConstData );
void operator+=( ConstPString string ) { operator+=( string.Text() ); }
void operator+=( const PString& string ) { operator+=( string.Text() ); }
void operator+=( const uint8 *string ) { operator+=( ConstPString( string ) ); }
operator const uint8 *() const { return space.Start(); }
operator ConstPString() const { return ConstPString( space.Start() ); }
operator Data() { return Text(); }
operator ConstData() const { return Text(); }
uint8 *Raw() { return static_cast<uint8*>( space.Start() ); }
void Remove( URange32 );
void Insert( uint32 where, uint8 c );
void Insert( uint32 where, ConstData );
void Insert( uint32 where, ConstPString string ) { Insert( where, string.Text() ); }
void Insert( uint32 where, PString string ) { Insert( where, string.Text() ); }
void Insert( uint32 where, const uint8 *string ) { Insert( where, ConstPString( string ) ); }
void Replace( URange32 where, uint8 c );
void Replace( URange32 where, ConstData );
void Replace( URange32 where, ConstPString string ) { Replace( where, string.Text() ); }
void Replace( URange32 where, PString string ) { Replace( where, string.Text() ); }
void Replace( URange32 where, const uint8 *string ) { Replace( where, ConstPString( string ) ); }
};
#endif